﻿ #define _CRT_SECURE_NO_WARNINGS 1

class Solution {
public:
	//分割字符串，将单词保存在vs
	void split_string(vector<string>& vs, string& s)
	{
		string::iterator it = s.begin();
		size_t start = 0;
		size_t pos = s.ﬁnd(' ');
		while (pos != string::npos)
		{
			string tmp(it + start, it + pos);
			vs.push_back(tmp);
			start = pos + 1;
			pos = s.ﬁnd(' ', pos + 1);
		}
		string tmp(it + start, it + s.size());
		vs.push_back(tmp);
	}
	//删除重复单词
	void erase_repeat_word(vector<string>& vs)
	{
		vector<string>::iterator slow = vs.begin();
		vector<string>::iterator fast = slow + 1;
		while (slow != vs.end())
		{
			if (*fast == *slow)
			{
				while (fast != vs.end() && *fast == *slow)
					fast++;
				slow = vs.erase(slow, fast);
				if (slow != vs.end())
					fast = slow + 1;
			}
			else
			{
				slow = fast;
				fast = slow + 1;
			}
		}
	}
	vector<string> uncommonFromSentences(string s1, string s2)
	{
		vector<string> vs;
		//提取s1单词
		split_string(vs, s1);
		//提取s2单词
		split_string(vs, s2);
		//对单词进行排序
		sort(vs.begin(), vs.end());
		//删除重复单词
		erase_repeat_word(vs);
		return vs;
	}
};